import java.util.Stack;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-11-13
 * Time: 18:56
 */
class MyQueue {

    int useSize;
    Stack<Integer> sta1;
    Stack<Integer> sta2;

//    构造方法
    public MyQueue() {
        sta1 = new Stack<>();
        sta2 = new Stack<>();
    }

//    入队
    public void push(int x) {
        sta1.push(x);
        this.useSize++;
    }

//    出队
    public int pop() {
        if (this.empty()){
            return -1;
        }
        if (sta2.isEmpty()){
            for (int i = 0; i < this.useSize; i++) {
                sta2.push(sta1.pop());
            }
        }
        this.useSize--;
        return sta2.pop();
    }

//    获取队列的栈顶元素
    public int peek() {
        if (this.empty()){
            return -1;
        }
        if (sta2.isEmpty()){
            for (int i = 0; i < this.useSize; i++) {
                sta2.push(sta1.pop());
            }
        }
        return sta2.peek();
    }

//    判断队列是否为空
    public boolean empty() {
        return this.useSize == 0;
    }
}
